package com.flymobi.service;

import java.sql.Types;
import java.util.Date;
import java.util.List;

import com.flymobi.fw.modules.CommonService;
import com.flymobi.po.Tongji;
import com.flymobi.util.QL;

public class TongjiService extends CommonService {

	public List<Tongji> list(Long type, Date startdate, Date enddate,
			int startRow, int pagePerSize) {
		return dao.find(Tongji.class, QL.HQL.Tongji.LIST, new Object[] { type,
				startdate, enddate }, startRow, pagePerSize);
	}
	
	public List<Tongji> listOrderByPv(Long type, Date startdate, Date enddate,
			int startRow, int pagePerSize) {
		return dao.find(Tongji.class, QL.HQL.Tongji.LIST_ORDER_BY_PV, new Object[] { type,
				startdate, enddate }, startRow, pagePerSize);
	}

	public Tongji find(Long type, Date date) {
		return dao.findSingle(Tongji.class, QL.HQL.Tongji.FIND, new Object[] {
				type, date });
	}

	public Long getCount(Long type, Date startdate, Date enddate) {
		return dao.getCount(QL.HQL.Tongji.GET_COUNT, new Object[] { type,
				startdate, enddate });
	}

	public void save(Tongji Tongji) {
		dao.save(Tongji);
	}

	public Tongji load(String id) {
		return dao.load(Tongji.class, new Long(id));
	}

	public Tongji get(String id) {
		return dao.get(Tongji.class, new Long(id));
	}

	public void delete(String id) {
		dao.delete(this.get(id));
	}

	public Long getPv(String day) {
		return dao.getCount(QL.HQL.ViewLog.get_pv, new Object[] { day });
	}
	
	public Long getUv(String day) {
		return dao.getCount(QL.HQL.ViewLog.get_uv, new Object[] { day });
	}
	
	public Long getIp(String day) {
		return dao.getCount(QL.HQL.ViewLog.get_ip, new Object[] { day });
	}

	public Long getHHPv(String day,String hour) {
		return dao.getCount(QL.HQL.ViewLog.get_hhpv, new Object[] { day,hour });
	}
	
	public Long getHHUv(String day,String hour) {
		return dao.getCount(QL.HQL.ViewLog.get_hhuv, new Object[] { day,hour });
	}
	
	public Long getHHIp(String day,String hour) {
		return dao.getCount(QL.HQL.ViewLog.get_hhip, new Object[] { day,hour });
	}

	public List<Object[]> listByVersion(Date date) {
		return dao.executeQueryBySQL(QL.SQL.MYSQL.TONGJI.TONGJI_BY_Version,
				new int[] { 91 }, new Object[] { date });
	}

	public Long getCountByDay(Date startdate, Date enddate) {
		return dao.getCountQueryBySQL(QL.SQL.MYSQL.TONGJI.getcountbyday,
				new int[] { 91, 91 }, new Object[] { startdate, enddate });
	}

	public List<Object[]> listPindao(Date date) {
		return dao.executeQueryBySQL(QL.SQL.MYSQL.TONGJI.TONGJI_BY_PINDAO,
				new int[] { 91}, new Object[] { date });
	}

	public List<Object[]> listPage(Long pindaoId, Date startdate, Date enddate) {
		return dao.executeQueryBySQL(QL.SQL.MYSQL.TONGJI.TONGJI_PAGE,
				new int[] { Types.BIGINT, 91, 91 }, new Object[] { pindaoId,
						startdate, enddate });
	}

	public List<Object[]> listLanmuPage(Long pindaoId, Date startdate,
			Date enddate) {
		return dao.executeQueryBySQL(QL.SQL.MYSQL.TONGJI.TONGJI_PAGE2,
				new int[] { Types.BIGINT, 91, 91, Types.BIGINT }, new Object[] {
						pindaoId, startdate, enddate, pindaoId });
	}

	public List<Object[]> listArea(Date startdate, Date enddate) {
		return dao.executeQueryBySQL(QL.SQL.MYSQL.TONGJI.TONGJI_Area,
				new int[] { 91, 91 }, new Object[] { startdate, enddate });
	}

	public List<Object[]> listQudao(Date startdate, Date enddate) {
		return dao.executeQueryBySQL(QL.SQL.MYSQL.TONGJI.TONGJI_Qudao,
				new int[] { 91, 91 }, new Object[] { startdate, enddate });
	}

	public List<Object[]> listAd(Date startdate, Date enddate) {
		return dao.executeQueryBySQL(QL.SQL.MYSQL.TONGJI.TONGJI_Ad, new int[] {
				91, 91 }, new Object[] { startdate, enddate });
	}

	/**
	 * @param l
	 * @param ts
	 */
	public void delete(long type, Date ts) {
		dao.executeUpdate("delete from Tongji m where m.type=? and m.date=?", new Object[]{type,ts});
	}
}
